`
https://leetcode.cn/problems/compare-strings-by-frequency-of-the-smallest-character/
`

/**
 * @param {string[]} queries
 * @param {string[]} words
 * @return {number[]}
 */
var numSmallerByFrequency = function (queries, words) {
  // 计算 words 里面每个字符串中最小字母出现的频次
  // 预先排序，方便二分
  words = words.map((word) => f(word)).sort((a, b) => a - b)
  // 对每个 query，计算最小字母出现的频次，然后二分查找比它大的个数
  return queries.map((query) => words.length - _.sortedIndex(words, f(query) + 1))
};

function f(s) {
  let minCh = s[0]
  let minCount = 1
  for (let i = 1; i < s.length; i++) {
    const c = s[i]
    if (c < minCh) {
      minCh = c
      minCount = 1
      continue
    }
    if (c === minCh) minCount++
  }
  return minCount
}